home *** CD-ROM | disk | FTP | other *** search
- /*
- File: HistoryExport.c
-
- Copyright 1990 by Thomas Knoll.
- Copyright 1993 by Adobe Systems, Inc.
-
- C source file for HistoryExport example.
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <Packages.h>
- #include <Errors.h>
- #include <ToolUtils.h>
-
- #include "PITypes.h"
- #include "PIGeneral.h"
- #include "PIExport.h"
-
- #include "DialogUtilities.h"
- #include "PIUtilities.h"
-
- #ifdef THINK_C
-
- #define ENTRYPOINT main
-
- #endif
-
- /*****************************************************************************/
-
- typedef struct Globals
- {
-
- short result;
- ExportRecord *stuff;
-
- short fRefNum;
- short vRefNum;
-
- } Globals, *GPtr;
-
- #define gResult ((*globals).result)
- #define gStuff ((*globals).stuff)
-
- #define gFRefNum ((*globals).fRefNum)
- #define gVRefNum ((*globals).vRefNum)
-
- /*****************************************************************************/
-
- void InitGlobals (GPtr globals);
-
- void DoAbout (GPtr globals);
- void DoPrepare (GPtr globals);
- void DoStart (GPtr globals);
- void DoContinue (GPtr globals);
- void DoFinish (GPtr globals);
-
- /*****************************************************************************/
-
- /* All calls to the plug-in module come through this routine. It must be
- placed first in the resource. To achieve this, most development systems
- require that this be the first routine in the source. */
-
- pascal void ENTRYPOINT (short selector,
- ExportRecord *stuff,
- long *data,
- short *result)
- {
-
- GPtr globals;
-
- if (!*data)
- {
-
- *data = (long) NewPtr (sizeof (Globals));
-
- if (!*data)
- {
- *result = memFullErr;
- return;
- }
-
- InitGlobals ((GPtr) *data);
-
- }
-
- globals = (GPtr) *data;
-
- gStuff = stuff;
- gResult = noErr;
-
- switch (selector)
- {
-
- case exportSelectorAbout:
- DoAbout (globals);
- break;
-
- case exportSelectorPrepare:
- DoPrepare (globals);
- break;
-
- case exportSelectorStart:
- DoStart (globals);
- break;
-
- case exportSelectorContinue:
- DoContinue (globals);
- break;
-
- case exportSelectorFinish:
- DoFinish (globals);
- break;
-
- default:
- gResult = exportBadParameters;
-
- }
-
- *result = gResult;
-
- }
-
- /*****************************************************************************/
-
- void InitGlobals (GPtr globals)
- {
-
- #pragma unused (globals)
-
- /* None of the globals requires initialization. */
-
- }
-
- /*****************************************************************************/
-
- /* Displays the about dialog box for the plug-in module. */
-
- void DoAbout (GPtr globals)
- {
-
- #pragma unused (globals)
-
- #define dialogID 17000
-
- ShowAbout (dialogID);
-
- #undef dialogID
-
- }
-
- /*****************************************************************************/
-
- /* Prepare to export an image. If the plug-in module needs only a limited
- amount of memory, it can lower the value of the 'maxData' field. */
-
- void DoPrepare (GPtr globals)
- {
-
- gStuff->maxData = 0;
-
- }
-
- /*****************************************************************************/
-
- static void GetHistory (GPtr globals, int16 index, Str255 string)
- {
-
- string [0] = 0;
-
- if (CountPIResources ('hist') >= index)
- {
-
- Handle h = GetPIResource ('hist', index);
-
- if (h)
- {
-
- int32 length = PIGetHandleSize (h);
-
- if (length > 255)
- length = 255;
-
- if (length > 0)
- {
-
- BlockMove (*h, &(string [1]), length);
-
- string [0] = (unsigned char) length;
-
- }
-
- }
-
- }
-
- }
-
- /*****************************************************************************/
-
- /* Requests pointer to the first part of the image to be filtered. */
-
- void DoStart (GPtr globals)
- {
-
- #define dialogID 17001
- #define trimFirst 3
- #define trimLast 4
- #define hookItem 5
- #define histItem1 6
- #define histItem2 7
- #define histItem3 8
- #define histItem4 9
-
- Str255 history1;
- Str255 history2;
- Str255 history3;
- Str255 history4;
- short item;
- DialogPtr dp;
- DialogTHndl dt;
-
- gStuff->theRect.top =
- gStuff->theRect.left =
- gStuff->theRect.bottom =
- gStuff->theRect.right = 0;
-
- if (!WarnResourceProcsAvailable ())
- return;
-
- dt = (DialogTHndl) GetResource ('DLOG', dialogID);
- HNoPurge ((Handle) dt);
-
- CenterDialog (dt);
- SetUpMoveableModal (dt, gStuff->hostSig);
-
- dp = GetNewDialog (dialogID, nil, (WindowPtr) -1);
-
- SetOutlineOKHook (dp, hookItem);
-
- do
- {
-
- GetHistory (globals, 1, history1);
- GetHistory (globals, 2, history2);
- GetHistory (globals, 3, history3);
- GetHistory (globals, 4, history4);
-
- ParamText (history1, history2, history3, history4);
-
- if (CountPIResources ('hist') > 0)
- {
- EnableControl (dp, trimFirst);
- EnableControl (dp, trimLast);
- }
- else
- {
- DisableControl (dp, trimFirst);
- DisableControl (dp, trimLast);
- }
-
- MoveableModalDialog (dp, gStuff->processEvent, nil, &item);
-
- if (item == trimFirst && CountPIResources ('hist') > 0)
- {
-
- DeletePIResource ('hist', 1);
-
- InvalItem (dp, histItem1);
- InvalItem (dp, histItem2);
- InvalItem (dp, histItem3);
- InvalItem (dp, histItem4);
-
- }
-
- if (item == trimLast && CountPIResources ('hist') > 0)
- {
-
- DeletePIResource ('hist', CountPIResources ('hist'));
-
- InvalItem (dp, histItem1);
- InvalItem (dp, histItem2);
- InvalItem (dp, histItem3);
- InvalItem (dp, histItem4);
-
- }
-
- }
- while (item != ok && item != cancel);
-
- DisposDialog (dp);
- HPurge ((Handle) dt);
-
- #undef dialogID
- #undef trimItem
- #undef hookItem
-
- }
-
- /*****************************************************************************/
-
- /* Filters the area and requests the next area. */
-
- void DoContinue (GPtr globals)
- {
-
- #pragma unused (globals)
-
- }
-
- /*****************************************************************************/
-
- /* This routine will always be called if DoStart does not return an error
- (even if DoContinue returns an error or the user aborts the operation).
- This allows the module to perform any needed cleanup. None is required
- in this example. */
-
- void DoFinish (GPtr globals)
- {
-
- #pragma unused (globals)
-
- }
-
- /*****************************************************************************/
-